<template>
	<view>
		<view style=" width: 100%; display: flex; flex-direction: row;  " >
			<button class="btn" @click="appointment()"> 查看预约</button>
			<button class="btn" @click="commentsmage()"> 管理评论</button>
			<button class="btn" @click="gohome()"> 返回首页</button>
		</view>
		<view class="ryxq">
			<view class="xq-title" style="position: relative;">管理评论</view>
			<view class="xq-list" v-for="item in data" :key="item._id" > 
			<view v-if="item.user!= undefind ">
				<view class="items">评论人：{{item.user}}</view>
				<view class="items">评论：{{item.comment}}</view>
				<view class="items" >评论时间：{{item.create_time}}</view>
				<button class="itemss" size="mini" @click="deleteone(item)">删除评论</button>
			</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data:[],
			}
		},
		methods: {
			gohome(){
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			appointment(){
				this.$util.navigateTo('../data/data');
			},
			deleteone(id){
				var that = this;
				uni.showModal({
					title: '确认删除？',
					success: function(res) {
						if (res.confirm) {
							uniCloud.callFunction({
								name: 'comment_del',
								data:{
									id: id
								},
								success: (res) => {
									uni.showToast({
										title: '删除成功',
									})
									that.commentsmage();
								},
								fail: (err) => {
									console.log(err);
									uni.showToast({
										title: '删除失败，请稍后重试',
										icon: 'none'
									})
								},
								complete: (c) => {
									//console.log(c)
								}
							})
						}else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			commentsmage(){
				var that = this;
				uniCloud.callFunction({
					name: 'comment_read',
					success: (res) => {
						let {data} = res.result;
						this.data = data;
						console.log(res.result);
						uni.showToast({
							title: '请求成功',
						})
						//that.$util.navigateTo('../detailed/detailed');
					},
					fail: (err) => {
						console.log(err);
						uni.showToast({
							title: '请求失败，请稍后重试',
							icon: 'none'
						})
					},
					complete: (c) => {
					}
				})
			}
		}
	}
</script>

<style>
	.btn{
		font-size:32rpx;
		text-align:center;
		color:white;
		background-color:#0055ff;
		height: 80rpx;
		line-height: 80rpx;
		width:200rpx;
		float: left;
	}
	page {
		background: #ffffff;
	}
	
	.ryxq {
		display: flex;
		width: 100%;
		background: #ffffff;
		flex-direction: column;
		overflow: auto;
	}
	
	.xq-list {
		flex-direction: row;
		font-size: 30upx;
		line-height: 60upx;
		flex-wrap: wrap;
		height: auto;
		border-bottom: #cccccc 2upx solid;
	}
	
	.items {
		float: left;
		overflow: hidden;
		background: #efefef;
		margin: 20upx 20upx 0upx 20upx;
		padding: 5upx 15upx 5upx 15upx;
		border-radius: 20upx;
	}
	.itemss {
		background-color:#0055ff;
		color: #ffffff;
		float: right;
		height: 50upx;
		font-size:28rpx;
		line-height: 50upx;
		margin: 20upx 40upx 0upx 20upx;
		padding: 5upx 15upx 5upx 15upx;
	}
	
	.xq-title {
		padding: 20upx;
		border-bottom: #cccccc 2upx solid;
	}
</style>

